package com.tanguy.driver.base

import android.support.design.widget.TabLayout
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.View
import com.tanguy.driver.R
import com.tanguy.user.utlis.extend.click
import org.jetbrains.anko.find

/**
 * Created by dab on 2017/10/9 0009 14:42
 */
abstract class TabLayoutActivity : ImmersionTitleActivity() {
    override fun setContentViewRes(): Int = R.layout.activity_tab
    val tabLayout by lazy {
        find<TabLayout>(R.id.tab_title)
    }
    open val mRvContent by lazy {
        find<RecyclerView>(R.id.rv_content)
    }

    abstract fun getTabString(): ArrayList<String>
    abstract fun onTabItemSelected(position: Int)
    override fun initView() {
        super.initView()
        titleBar.visibility = View.GONE
        click(R.id.tv_back) { finish() }
        tabLayout.apply {
            getTabString().map {
                addTab(newTab().setText(it))
            }
//            addTab(tabLayout.newTab().setText("平台公告"))
//            addTab(tabLayout.newTab().setText("系统消息"))
        }
    }

    override fun initEvent() {
        super.initEvent()
        mRvContent.layoutManager = LinearLayoutManager(this)
        tabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
            override fun onTabSelected(tab: TabLayout.Tab) {
                onTabItemSelected(tab.position)
            }

            override fun onTabReselected(tab: TabLayout.Tab?) {
            }

            override fun onTabUnselected(tab: TabLayout.Tab?) {
            }
        })
//        tabLayout.getTabAt(0)!!.select()
        onTabItemSelected(0)//上面设置默认选中项不起作用,所以手动调用下

    }
}